<?php
// +----------------------------------------------------------------------
// |  [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\meeting\controller;

use cmf\controller\AdminBaseController;
use function Sodium\increment;
use think\Db;

class HireController extends AdminBaseController
{


    /*
     * 租赁服务列表
     * */
    public function index()
    {
        $where=[];
        $where[]=['title','like','%'. input('keyword','') .'%'];
        $data = Db::table('ims_hc_meet')
            ->where($where)
            ->paginate(10);
        $page  =  $data->render();
        $list  = $data->toArray();

        $this->assign('list',$list['data']);
        $this->assign('page',$page);
        return $this->fetch();

    }

    /*
     * lists
     * @param
     * $return
     */
    public function lists()
    {
        if(input('meeting_id')){
            session('MEETING_ID',input('meeting_id'));
        }
        $where[] = ['meeting_id','=', session('MEETING_ID')];
        $where[] = ['hire_name','like', '%'.input('hire_name','').'%'];
        $list  =  Db::table('ims_hc_meet_hire')
            ->where($where)
            ->select()->toArray();


        $this->assign('list',$list);
        return $this->fetch();
    }

    /*
     * 编辑
     * edit
     * @param
     * $return
     */
    public function edit()
    {
        if($this->request->isPost()){
            $data = input();
            $re = Db::table('ims_hc_meet_hire')->where('id',$data['id'])->update($data);
            $this->success('成功');exit();
        }
        $id = input('id');
        $info =  Db::table('ims_hc_meet_hire')->find($id);
        $class_list =  Db::table('ims_hc_meet_hire_class')->select();
        $type = [
            1 => '服务',
            2 => '证件',
            3 => '加班',
            4 => '审图',
            5 => '保险',
//    6 => '酒店',
        ];
        $this->assign('info',$info);
        $this->assign('type',$type);
        $this->assign('class_list',$class_list);
        return $this->fetch();
    }

    /*
     *
     * dele
     * @param
     * $return
     */
    public function dele()
    {
        $id = input('id');
        Db::table('ims_hc_meet_hire')->where('id',$id)->delete();
        $this->success('成功');exit();
    }

    /*
     * 添加
     * edit
     * @param
     * $return
     */
    public function add()
    {
        if($this->request->isPost()){
            $data = input();
            if (empty($data['hire_name'])) {
                $this->error('服务名称不能为空');
            }

            if (empty($data['class_id'])) {
                $this->error('请选择服务分类');
            }

            $data['meeting_id'] = session('MEETING_ID');
            $re = Db::table('ims_hc_meet_hire')->insert($data);
            $this->success('成功');exit();
        }
        $class_list =  Db::table('ims_hc_meet_hire_class')->select();
        $type = [
            1 => '服务',
            2 => '证件',
            3 => '加班',
            4 => '审图',
            5 => '保险',
//    6 => '酒店',
        ];
        $this->assign('type',$type);
        $this->assign('class_list',$class_list);
        return $this->fetch();
    }

    /*
     * 分类列表
     * classList
     * @param
     * $return
     */
    public function classList()
    {
        $where[] = ['meeting_id','=', input('meeting_id',1)];
        $list = Db::table('ims_hc_meet_hire_class')
            ->where($where)
            ->select()->toArray();
        $this->assign('list',$list);
        return $this->fetch();
    }

    /*
     * 分类添加
     * classAdd
     * @param
     * $return
     */
    public function class_add()
    {
        if($this->request->isPost()){
            $data = input();
            if (empty($data['class_name'])) {
                $this->error('服务分类名称不能为空');
            }
            $data['meeting_id'] = session('MEETING_ID');

            if($data['class_id']){
                $re = Db::table('ims_hc_meet_hire_class')->where('class_id',$data['class_id'])->update($data);
            }else{
                $re = Db::table('ims_hc_meet_hire_class')->insert($data);

            }

            $this->success('成功');exit();
        }
    }


    public function class_dele()
    {
        $id = input('class_id');
        Db::table('ims_hc_meet_hire_class')->where('class_id',$id)->delete();
        $this->success('成功');exit();
    }

}